package zxingdemo.com.testzxing;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.google.zxing.client.android.CaptureActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.tv)
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);



    }

    public void bt(View view) {
        //
        //startActivity(new Intent(this, CaptureActivity.class));

        startActivityForResult(new Intent(this, CaptureActivity.class), 200);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        //下面这个是防止崩溃
        if (data == null) {
            return;
        }
        if (resultCode == RESULT_OK && requestCode == 200) {
            String qrcode = data.getStringExtra("qrcode");
            tv.setText(qrcode);

        }
    }
}
